<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
    <p><input type="text" id="txtAccount" placeholder="account"></p>
    <p><input type="password" id="txtPassword" placeholder="password"></p>
    <p><input type="button" value="登录" id="btnLogin"></p>

</div>
</body>
<script src="js/jquery-3.2.1.js"></script>
<script src="js/layer/layer.js"></script>

<script>
    $(function () {
        $('#btnLogin').on('click', function () {
            if ($('#txtAccount').val() == '' || $('#txtPassword').val() == '') {
                layer.msg('请输入完整信息');
                return;
            }

            $.post('login.do', {
                account: $('#txtAccount').val(),
                password: $('#txtPassword').val()
            }, function (data) {
                //console.log(data);

                if (data.code == 200) {
                    sessionStorage.setItem('user',JSON.stringify(data.result));
                    layer.msg(data.msg, {icon: 1, time: 2000}, function () {
                        location.href = "main.html";
                    })
                } else {
                    layer.msg(data.msg);
                }
            }, "JSON");
        })
    })
</script>
</html>